#ifndef _FLASH_DRAW_HELPER_H_
#define _FLASH_DRAW_HELPER_H_


class FlashDrawHelper
{
public:
	static void SetTextureColor(HGTEXTURE hTex, xARGB x, LPCRECT pRect)
	{
		BITMAP bmp;
		if (LockTextureBits(hTex, &bmp, pRect))
		{
			for (int j = 0; j < bmp.bmHeight; j++)
			{
				LPXARGB lpPixel = LPXARGB((LPBYTE)bmp.bmBits + j * bmp.bmWidthBytes);
				for (int i = 0; i < bmp.bmWidth; i++)
				{
					*lpPixel++ = x;
				}
			}
			UnlockTextureBits(hTex, pRect);
		}
	}

	static void CalcAlpha(HGTEXTURE hTexZero, HGTEXTURE hTexFull, LPCRECT pRect)
	{
		BITMAP bmpZero;
		BITMAP bmpFull;
		if (LockTextureBits(hTexZero, &bmpZero, pRect))
		{
			if (LockTextureBits(hTexFull, &bmpFull, pRect))
			{
				if ((bmpZero.bmWidth == bmpFull.bmWidth) &&
					(bmpZero.bmHeight == bmpFull.bmHeight))
				{
					for (int j = 0; j < bmpZero.bmHeight; j++)
					{
						LPXARGB lpPixelZero = (LPXARGB)((LPBYTE)bmpZero.bmBits + j * bmpZero.bmWidthBytes);
						LPXARGB lpPixelFull = (LPXARGB)((LPBYTE)bmpFull.bmBits + j * bmpFull.bmWidthBytes);
						for (int i = 0; i < bmpZero.bmWidth; i++)
						{
							lpPixelZero->alpha = 0xFF + lpPixelZero->red - lpPixelFull->red;
							lpPixelZero++;
							lpPixelFull++;
						}
					}
				}
				UnlockTextureBits(hTexFull, pRect);
			}
			UnlockTextureBits(hTexZero, pRect);
		}
	}

	static void FillAlpha(HGTEXTURE hTex, LPCRECT pRect)
	{
		BITMAP bmp;
		if (LockTextureBits(hTex, &bmp, pRect))
		{
			for (int j = 0; j < bmp.bmHeight; j++)
			{
				LPXARGB lpPixel = (LPXARGB)((LPBYTE)bmp.bmBits + j * bmp.bmWidthBytes);
				for (int i = 0; i < bmp.bmWidth; i++)
				{
					lpPixel->alpha = 0xFF;
				}
			}
			UnlockTextureBits(hTex, pRect);
		}
	}
};

#endif